home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 234_01 / display.c < prev    next >
Text File  |  1987-06-16  |  12KB  |  485 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     XDIR - Hard Disk Manager
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Apr 03, 1987
  6.   DESCRIPTION:     Hard Disk Manager for IBM PC
  7.   KEYWORDS:     Hard Disk Manager Dump Directory
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      display.c
  10.   WARNINGS:     None
  11.   CRC:         N/A
  12.   SEE-ALSO:     HDIR.DOC and XDIR.DOC
  13.   AUTHOR:     Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
  14.   COMPILERS:     ECO-C
  15.   REFERENCES:     XDIR.DOC
  16. */
  17.  
  18.  
  19. /*
  20.   display
  21.   display a screen and accept the answers
  22.  
  23. */
  24. #include "stdio.h"
  25. #include "dir.h"
  26. #include "xdir.h"
  27. extern char cdir[];
  28. extern char helpfile[];
  29. /*
  30.    disx
  31.    handle display and maintenance of files
  32. */
  33. void disx(text,pcount,answer,typx)
  34. struct tdir *text[];
  35. int  pcount;   /* number of elements */
  36. char *answer;  /* array of answers */
  37. int  typx;      /* 1 = dir , 2 = files */
  38. {
  39.  
  40.      int  i,c,row,col,ct;
  41.      struct tdir *tp;
  42.      int  brkey;          /* break key */
  43.  
  44.      brkey = 0;
  45.      while (1)
  46.      {
  47.      display(text,answer,pcount,typx);   /* process the parameters */
  48.      for(i=ct=0;i<MAXFILE;i++)
  49.        if (answer[i] != ' ') ++ct;
  50.      if (ct == 0) break;
  51.      if (typx == 1) break;  /* nothing further for DIR */
  52.  
  53.      clrscr();
  54.      boxx(79,24,1,1);
  55.      cursor(2,20);
  56.      writestr("Hard Disk File Manager - Verify Options ");
  57.      row = 4;
  58.      col = 20;
  59.  
  60.  
  61.      for (i=0;i<MAXFILE;i++)
  62.      {
  63.  
  64.      if (row > 20)
  65.         {
  66.         cursor(row,col);
  67.         writestr("Press any key for next page or 'X' to cancel ");
  68.         c = getch();
  69.         if (c == 'X') {brkey = 1; break;}
  70.         clrscr();                           /* fresh screen */
  71.         boxx(79,24,1,1);
  72.         cursor(2,20);
  73.         writestr("Hard Disk File Manager - Verify Options ");
  74.         row = 4;
  75.         }
  76.  
  77.      if (brkey) break;
  78.      c = (int) answer[i];
  79.      tp = text[i];
  80.      switch (c)
  81.        {
  82.        case 'X':     /* delete */
  83.        case 'L':     /* list */
  84.        case 'T':     /* type */
  85.        case 'R':     /* rename */
  86.        case 'C':     /* copy */
  87.        case 'D':     /* dump */
  88.        case 'P':     /* protect */
  89.        case 'H':     /* hide */
  90.        case 'U':     /* unhide */
  91.        case 'W':     /* unprotect */
  92.        case 'E':     /* encrypt */
  93.        case 'S':     /* search */
  94.          cursor(row++,col);
  95.          writestr("File ");
  96.          writestr(tp->d_name);
  97.          writestr(" will be ");
  98.          break;
  99.      }     /* end switch */
  100.  
  101.      switch (c)
  102.        {
  103.        case 'X':
  104.          writestr("deleted ");
  105.          break;
  106.        case 'L':
  107.          writestr("listed ");
  108.          break;
  109.        case 'T':
  110.          writestr("typed ");
  111.          break;
  112.        case 'R':
  113.          writestr("renamed ");
  114.          break;
  115.        case 'C':
  116.          writestr("copied ");
  117.          break;
  118.        case 'D':
  119.          writestr("dumped ");
  120.          break;
  121.        case 'P':
  122.          writestr("protected");
  123.          break;
  124.        case 'W':
  125.          writestr("unprotected ");
  126.          break;
  127.        case 'U':
  128.          writestr("unhidden ");
  129.          break;
  130.        case 'H':
  131.          writestr("hidden ");
  132.          break;
  133.        case 'E':
  134.          writestr("encrypted ");
  135.          break;
  136.        case 'S':
  137.          writestr("searched ");
  138.          break;
  139.      }     /* end switch */
  140.  
  141.      }     /* end while */
  142.  
  143.      if (brkey) break;
  144.      cursor(row,col);
  145.      writestr("Continue processing? (Y)es (N)o ");
  146.      i = toupper(getch());
  147.      if (i == 'Y') break;
  148.      }     /* end while 1 */
  149. }
  150. /*
  151.   display
  152.   display filenames on multiple pages
  153. */
  154. void display(text,answer,fcount,typx)
  155. struct tdir *text[];
  156. char *answer;
  157. int  fcount;
  158. int  typx;     /* 1 = directories , 2 = files */
  159. {
  160.       int i, row, col;
  161.       int  c, cntl;
  162.       char disp[60];
  163.       int  pageno;       /* page number 0 - x */
  164.       int  ff, lf;       /* first and last field number */
  165.       struct tdir *tp;
  166.  
  167.       pageno = 0;        /* initialize page */
  168.  
  169.       while (1)          /* main loop */
  170.       {
  171.       if (pageno < 0) pageno = 0;
  172.       if ((pageno*72) > fcount) pageno = 0;
  173.       ff = pageno * 72;
  174.       lf = ff + 71;
  175.       if (lf >= fcount) lf = fcount-1;
  176.       lf -= (pageno*72);
  177.  
  178.       clrscr();
  179.       boxx(79,24,1,1);
  180.       cursor(2,20);
  181.       writestr("Hard Disk File Manager - Directory ");
  182.       tp = text[0];
  183.       if (typx == 1) writestr("**ROOT**");
  184.           else writestr(cdir);          /* display directory */
  185.       cursor(22,4);
  186.  
  187.       if (typx == 2)
  188.       {
  189.       writestr("Options: <CR> = end, F1 = Help ");
  190.       writestr(" X = delete, (L)ist (T)ype (R)ename (S)earch");
  191.       cursor(24,4);
  192.       writestr("(C)opy (D)ump (H)ide, (U)nhide, (P)rotect, (W)rite (E)ncrypt ");
  193.       }
  194.       else writestr("Options: <CR> = end, (S)elect F1 = Help");
  195.  
  196.       cursor(23,4);
  197.       writestr("PgUp = previous display PgDn = next");
  198.  
  199.  
  200.       for (i=0;i<=lf;i++)    /* display the file names */
  201.       {
  202.       col = ((i/18)*20)+2;
  203.       row = (i % 18) + 3;
  204.       cursor(row,col);
  205.       putchar('[');
  206.       putchar(answer[ff+i]);
  207.       putchar(']');
  208.       putchar(' ');
  209.       tp = text[ff+i];
  210.       if (((ff+i) == 0) && (typx == 1)) strcpy(disp,"**ROOT**");
  211.       else strcpy(disp,tp->d_name);
  212.       if (tp->d_attrib & 0x02)  /* hidden */
  213.          writestr("\033[7m");
  214.       writestr(disp);
  215.       if (tp->d_attrib & 0x02) writestr("\033[0m");
  216.       }
  217.  
  218.       i = 0;                          /* initialize field number */
  219.       while (1)                       /* maintain the options */
  220.       {
  221.       col = ((i/18)*20)+3;
  222.       row = (i%18) +3;
  223.       cursor(row,col);
  224.       if ((c=getch()) == 0)
  225.          {cntl = 1;c=getch();}
  226.       else cntl = 0;
  227.  
  228.       switch (cntl)
  229.       {
  230.       case 0:                        /* a normal character was entered */
  231.         c = toupper(c);
  232.         if ((typx == 2) && (c == 0x0d)) break;
  233.         if (isval(c,typx))   /* verify valid response */
  234.           {
  235.           answer[ff+i] = c;
  236.           putchar(c);
  237.           }
  238.         if ((typx == 1) && (c == 'S')) return;
  239.         break;
  240.       case 1:                       /* extended character was entered */
  241.         if (c == 0x48) --i;                             /* up arrow */
  242.         if (c == 0x50) ++i;                             /* down arrow */
  243.         if (c == 0x4b) i -= 18;                         /* left arrow */
  244.         if (c == 0x4d) i += 18;                         /* right arrow */
  245.         if (c == 0x47) i = 0;                           /* home */
  246.         if (c == 0x49) --pageno;                        /* page up */
  247.         if (c == 0x51) ++pageno;                        /* page down */
  248.         if (c == 0x3b) xhelp(typx);                     /* display help */
  249.         break;
  250.       }                   /* end switch */
  251.  
  252.       if (c == 0x0d) break;  /* CR */
  253.       if ((c == 0x49) || (c== 0x51)) break;      /* PgUp PgDn */
  254.       if (c == 0x3b) break;  /* F1 */
  255.       if (i<0) i = 0;
  256.       if (i>=lf) i = lf;
  257.       }   /* end while  main options */
  258.       if (c == 0x0d) break;  /* CR */
  259.       }   /* end while -  main loop */
  260. }
  261.  
  262. /*
  263.    isval
  264.    is a valid response
  265.  
  266. */
  267. isval(c,typx)
  268. int  c;
  269. int  typx;  /* 1 = directories, 2 = files */
  270. {
  271.  
  272.     if (typx == 2)       /* files */
  273.     {
  274.     switch (c)
  275.     {
  276.       case ' ':
  277.       case 'X':          /* delete */
  278.       case 'L':          /* list */
  279.       case 'T':          /* type */
  280.       case 'R':          /* rename */
  281.       case 'C':          /* copy */
  282.       case 'D':          /* dump */
  283.       case 'P':          /* protect */
  284.       case 'U':          /* unhide */
  285.       case 'W':          /* write */
  286.       case 'H':          /* hide */
  287.       case 'E':          /* encrypt */
  288.       case 'S':          /* search */
  289.         return (1);
  290.         break;
  291.       default:
  292.         return (0);
  293.         break;
  294.       }   /* end case */
  295.     }  /* end if type is 2 - files */
  296.  
  297.    else
  298.    {
  299.     if ((c== ' ') || (c == 'S')) return (1);
  300.     else return (0);
  301.    }      /* end else */
  302.  
  303. }         /* end function */
  304. /*
  305.   cv